package com.changgou.search.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfiguration {
    //存放发生改变的广告信息缓存的队列名称
    public static final String AD_UPDATE_QUEUE="ad_update_queue";
    @Bean(AD_UPDATE_QUEUE)
    public Queue AD_UPDATE_QUEUE(){
        return new Queue(AD_UPDATE_QUEUE);
    }

    //上架商品的交换机和队列名称
    public static final String SEARCH_ADD_QUEUE="search_add_queue";
    public static final String GOODS_UP_EXCHANGE="goods_up_exchange";
    @Bean(SEARCH_ADD_QUEUE)
    public Queue SEARCH_ADD_QUEUE(){
        return new Queue(SEARCH_ADD_QUEUE);
    }
    @Bean(GOODS_UP_EXCHANGE)
    public Exchange GOODS_UP_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(GOODS_UP_EXCHANGE).durable(true).build();
    }
    @Bean
    public Binding GOODS_UP_EXCHANGE_BINDING(@Qualifier(GOODS_UP_EXCHANGE) Exchange exchange,@Qualifier(SEARCH_ADD_QUEUE)Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

    //下架商品的交换机和队列名称
    public static final String SEARCH_DELETE_QUEUE="search_delete_queue";
    public static final String GOODS_DOWN_EXCHANGE="goods_down_exchange";
    @Bean(SEARCH_DELETE_QUEUE)
    public Queue SEARCH_DELETE_QUEUE(){
        return new Queue(SEARCH_DELETE_QUEUE);
    }
    @Bean(GOODS_DOWN_EXCHANGE)
    public Exchange GOODS_DOWN_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(GOODS_DOWN_EXCHANGE).durable(true).build();
    }
    @Bean
    public Binding GOODS_DOWN_EXCHANGE_BINDING(@Qualifier(GOODS_DOWN_EXCHANGE) Exchange exchange,@Qualifier(SEARCH_DELETE_QUEUE)Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}
